(function(){"use strict";BX.namespace("BX.Landing.UI.Tool");var n=BX.Landing.Utils.slice;var t=BX.Landing.Utils.arrayUnique;var e=BX.Landing.Utils.data;var a=BX.Landing.Utils.isString;var o=BX.Landing.Utils.create;var r=BX.Landing.Utils.append;var i=BX.Landing.Utils.remove;BX.Landing.UI.Tool.FontManager=function(){};BX.Landing.UI.Tool.FontManager.getInstance=function(){return BX.Landing.UI.Tool.FontManager.instance||(BX.Landing.UI.Tool.FontManager.instance=new BX.Landing.UI.Tool.FontManager)};function s(n){return"g-font-"+n.toLowerCase().trim().replace(/ /g,"-")}function d(n,t){n=n.replaceAll("+"," ");var e={serif:'"#font#", serif',"sans-serif":'"#font#", sans-serif',display:'"#font#", cursive',handwriting:'"#font#", cursive',monospace:'"#font#", monospace'};return e[t]?e[t].replace("#font#",n):'"'+n+'"'}BX.Landing.UI.Tool.FontManager.prototype={getLoadedFonts:function(){var t=n(document.head.querySelectorAll('[data-font*="g-font-"]'));return t.map((function(n){return{className:e(n,"data-font"),element:n,CSSDeclaration:document.head.querySelector('[data-id*="'+e(n,"data-font")+'"]'),protected:e(n,"data-protected")||false}}))},getUsedLoadedFonts:function(){var n=[];var t=this.getLoadedFonts().filter((function(n){return!n.protected}));if(t.length){var e=this.getAllUsedFonts();t.forEach((function(t){var a=e.some((function(n){return t.className===n}));if(a){n.push(t)}}))}return n},getAllUsedFonts:function(e){e=e||document.body;var o=n(e.querySelectorAll("*:not(img)"));var r=[];o.forEach((function(n){var t=BX.style(n,"font-family");if(a(t)){t=t.replace(/['|"]/g,"");r.push(s(t.split(",")[0]))}}));return t(r)},isLoaded:function(n){return this.getLoadedFonts().some((function(t){return t.className===n}))},addFont:function(n,t){var e=!!t?t.document:document;return new Promise(function(t){if(!this.isLoaded(n.className)){let s=n.href;if(window.fontsProxyUrl){const n=new URL(s);n.host=window.fontsProxyUrl;s=n.href}var a=o("link",{attrs:{rel:"stylesheet",href:s,"data-font":n.className,media:"async@load"},events:{load:function(){this.media="all";t()},error:function(){t()}}});var i=o("style",{attrs:{"data-id":n.className},text:"."+n.className+" { font-family: "+d(n.family,n.category)+"; }"});r(a,e.head);r(i,e.head)}else{t()}}.bind(this))},getUnusedLoadedFonts:function(){var n=[];var t=this.getLoadedFonts().filter((function(n){return!n.protected}));if(t.length){var e=this.getAllUsedFonts();t.forEach((function(t){var a=e.some((function(n){return t.className===n}));if(!a){n.push(t)}}))}return n},removeUnusedFonts:function(){this.getUnusedLoadedFonts().forEach((function(n){if(n.element){i(n.element)}if(n.CSSDeclaration){i(n.CSSDeclaration)}}))}}})();
//# sourceMappingURL=font-manager.map.js